package com.bdqn.controller;

import com.bdqn.pojo.Dept;
import com.bdqn.service.DeptService;
import com.bdqn.util.TokenUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin //允许跨域
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    DeptService deptService;
    @Autowired
    TokenUtil tokenUtil;
    //查询所有
    @GetMapping("/getDept")
    public PageInfo<Dept> getDept(int pageNum,int pageSize,String dname){
        PageInfo<Dept> pageInfo=deptService.selectPage(pageNum,pageSize,dname);
        return pageInfo;
    }

    //添加科室
    @PostMapping("/addDept")
    public int addDept(@RequestBody Dept dept,@RequestHeader("token") String token){
        String uname=tokenUtil.getUname(token);
        dept.setCreateBy(uname);
        int row=deptService.addDept(dept);
        return row;
    }

    //修改科室
    @PostMapping("/updateDept")
    public int updateDept(@RequestBody Dept dept,@RequestHeader("token") String token){
        String uname=tokenUtil.getUname(token);
        dept.setUpdateBy(uname);
        int row=deptService.updateDept(dept);
        return row;
    }

    //删除科室
    @GetMapping("/deleteDept")
    public int deleteDept(int deptId){
        int row=deptService.deleteDept(deptId);
        return row;
    }

    //修改状态
    @GetMapping("/updateStatus")
    public int updateStatus(int id,String status){
        int row=deptService.updateStatus(id,status);
        return row;
    }
}
